#!/usr/bin/env python

import rospy
import numpy as np
import math
import time
from math import pi
from sensor_msgs.msg import LaserScan


class Combination():
    def __init__(self):
        self.moving()

    def moving(self):
        k=0
        with open('/home/ifl/catkin_ws/src/turtlebot3_machine_learning/turtlebot3_dqn/results_experiments/sensor_data_6.csv', 'w+') as saveFile:
            # saveFile.write("Odom_X,Odom_Y,Map_X,Map_Y,Odom_YAW,Map_YAW" + '\n')
            saveFile.write("Messwerte" + '\n')  # wr
            while not rospy.is_shutdown():
                data = rospy.wait_for_message('scan', LaserScan, timeout=5)
                saveFile.write(str(data.ranges) + '\n')  # write each result to new line
                saveFile.flush()
                time.sleep(4)

def main():
    rospy.init_node("scan")
    try:
        combination = Combination()
    except rospy.ROSInterruptException:
        pass

if __name__ == '__main__':
    main()
